package com.lyx.contentprodiver

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView

class ContactAdapter(private val contactList: List<ContactEntity>) :
    RecyclerView.Adapter<ContactAdapter.ViewHolder>() {

    inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val mNameTv: TextView = view.findViewById(R.id.name_tv)
        val mPhoneNumberTv: TextView = view.findViewById(R.id.phone_number_tv)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ContactAdapter.ViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.item_contact, parent, false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: ContactAdapter.ViewHolder, position: Int) {
        val contact = contactList[position]
        holder.mNameTv.text = contact.name
        holder.mPhoneNumberTv.text = contact.phoneNumber
    }

    override fun getItemCount() = contactList.size
}